package com.speechb.common.logger;

import org.slf4j.Logger;

/**
 * 运行日志打印
 * @author : llj
 * @version :2.1.0
 * @date : 2019/7/31 19:52
 */
public class RunLogger {
    private static final Logger RUN_LOGGER = AppLoggerFactory.getRunLogger();
    public static boolean isDebugEnabled() {
        return RUN_LOGGER.isDebugEnabled();
    }

    public static void debug(String msg){
        RUN_LOGGER.debug(getPrintMessage(msg));
    }

    public static void debug(String format, Object... arguments){
        RUN_LOGGER.debug(getPrintMessage(format),arguments);
    }
    public static void debug(String msg, Throwable t){
        RUN_LOGGER.debug(getPrintMessage(msg),t);
    }
    public  static boolean isWarnEnabled() {
        return RUN_LOGGER.isWarnEnabled();
    }

    public static void warn(String msg){
        RUN_LOGGER.warn(getPrintMessage(msg));
    }

    public static void warn(String format, Object... arguments){
        RUN_LOGGER.warn(getPrintMessage(format),arguments);
    }
    public static void warn(String msg, Throwable t){
        RUN_LOGGER.warn(getPrintMessage(msg),t);
    }
    public  static boolean isInfoEnabled() {
        return RUN_LOGGER.isInfoEnabled();
    }

    public static void info(String msg){
        RUN_LOGGER.info(getPrintMessage(msg));
    }

    public static void info(String format, Object... arguments){
        RUN_LOGGER.warn(getPrintMessage(format),arguments);
    }
    public static void info(String msg, Throwable t){
        RUN_LOGGER.warn(getPrintMessage(msg),t);
    }
    public  static boolean isErrorEnabled() {
        return RUN_LOGGER.isErrorEnabled();
    }

    public static void error(String msg){
        RUN_LOGGER.error(getPrintMessage(msg));
    }

    public static void error(String format, Object... arguments){
        RUN_LOGGER.error(getPrintMessage(format),arguments);
    }
    public static void error(String msg, Throwable t){
        RUN_LOGGER.error(getPrintMessage(msg),t);
    }
    public static String getPrintMessage(String msg) {
        StackTraceElement element = new Throwable().getStackTrace()[2];
        return new StringBuilder().append("[")
                .append(element.getClassName())
                .append(".")
                .append(element.getMethodName())
                .append(":")
                .append(element.getLineNumber())
                .append("] ")
                .append(msg).toString();
    }
}
